/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc.example.bussines;

import java.util.List;
import mvc.example.bussines.domain.Student;
import mvc.example.bussines.domain.StudentStatus;
import mvc.example.persistence.dao.DAOFactory;
import mvc.example.persistence.dao.StudentDAO;
import mvc.example.persistence.dao.exception.DAOException;

/**
 *
 * @author Zeta
 */
public class StudentManager extends AbstractManager<Student> implements IStudentManager {

    
    
    
    @Override
    public Student inscribirAlumno(Student alumno) throws ManagerException {
        return null;
    }

    @Override
    public List<Student> getRegularStudents() throws ManagerException{
        StudentDAO studentDAO;
        try {
            studentDAO = DAOFactory.getDAO(StudentDAO.class);
        } catch (DAOException ex) {
            throw new ManagerException(ex.getMessage());
        }
        return studentDAO.getStudentsByStatus(StudentStatus.REGULAR);
    }

    @Override
    public void saveStudent(Student student) throws ManagerException{
        StudentDAO studentDAO;
        try {
            studentDAO = DAOFactory.getDAO(StudentDAO.class);
            if(student.isPersistent()){
                studentDAO.update(student);
            }else{
                studentDAO.save(student);
            }
        } catch (DAOException ex) {
            throw new ManagerException(ex.getMessage());
        }
    }
    
}
